package com.neu.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.neu.entity.SettleCategory;
import com.neu.service.SettleCategoryService;
import com.neu.util.JsonResult;
import com.neu.util.ResultCode;


@CrossOrigin
@RestController
@RequestMapping("/his/settlecategory")
public class SettleCategoryController {
	@Autowired
	private SettleCategoryService settleCategoryService;
	//		添加结算类别
	@PostMapping("/add_sc")
	public JsonResult<Boolean> addSettleCategory(@RequestBody String body) {
		SettleCategory settleCategory =JSON.parseObject(body,SettleCategory.class);
		boolean bbb=settleCategoryService.addSettleCategory(settleCategory);
		return  new JsonResult<Boolean>(ResultCode.SUCCESS,bbb);
	}
	//		删除结算类别根据id
	@PostMapping("/delete_sc")
	public JsonResult<Boolean> deleteSettleCategory (@RequestBody String body){
		JSONObject json=JSON.parseObject(body);
		int id=(int)json.get("id");
		boolean aaa=settleCategoryService.deleteSettleCategory(id);
		return new JsonResult<Boolean>(ResultCode.SUCCESS,aaa);
	}
	//		修改结算类别
	@PostMapping("/update_sc")
	public JsonResult<Boolean> updateSettleCategory(@RequestBody String body) {
		SettleCategory settleCategory =JSON.parseObject(body,SettleCategory.class);
		boolean ccc=settleCategoryService.updateSettleCategory(settleCategory);
		return  new JsonResult<Boolean>(ResultCode.SUCCESS,ccc);
	}
	//		分页查询 结算类别 ，支持根据类别名称进行搜索
	@PostMapping("/get_sc")
	public JsonResult<List<SettleCategory>> pageSettleCategory(@RequestBody String body) {
		JSONObject json=JSON.parseObject(body);
		int page=(int)json.get("page");
		int limit=(int)json.get("limit");
		String keyword= (String) json.get("keyword");
		List<SettleCategory> list = settleCategoryService.pageSettleCategory(page, limit, keyword);

		return new JsonResult<List<SettleCategory>>(ResultCode.SUCCESS,list) ;
	}


}
